//
//  RadioButtonTestCell.m
//  RadioButton
//
//  Created by cuibaoyin on 14-11-17.
//  Copyright (c) 2014年 cby. All rights reserved.
//

#import "RadioButtonCell.h"

@implementation RadioButtonCell

- (void)layoutSubviews
{
    CGFloat cellLabelWidth = self.frame.size.width - RadioCellImageViewLeftCap - RadioCellImageViewHeight - RadioCellImageViewAndTitleLabelCap;
    CGFloat cellLabelHeight = [RadioButtonCell heightForCellWithConstraintWidth:cellLabelWidth attibuteString:self.radioCell_label.attributedText];
    self.radioCell_imageview.frame = CGRectMake(RadioCellImageViewLeftCap, (cellLabelHeight - RadioCellImageViewHeight) * 0.5, RadioCellImageViewHeight, RadioCellImageViewHeight);
    self.radioCell_label.frame = CGRectMake(self.radioCell_imageview.frame.origin.x + self.radioCell_imageview.frame.size.width + RadioCellImageViewAndTitleLabelCap, 0, cellLabelWidth, cellLabelHeight);
    
    [super layoutSubviews];
}

+ (CGFloat)heightForCellWithConstraintWidth:(CGFloat)width attibuteString:(NSAttributedString *)attrString
{
    CGRect rect = [attrString boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading context:nil];
    
    return (rect.size.height > RadioCellImageViewHeight ? rect.size.height : RadioCellImageViewHeight) + RadioCellAndCellCap;
}


@end
